// type JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue };
type Obj = Record<string, JSONValue> | Array<JSONValue>;

function compactObject(obj: Obj): Obj {
    for (const objKey in obj) {
        if(obj[objKey] instanceof Object) compactObject(obj[objKey])
        else if(!Boolean(obj[objKey])){
            delete obj[objKey]
        }
    }
    console.log(JSON.stringify(obj))
    return  JSON.parse(JSON.stringify(obj).replaceAll(/,?null/g,''))
};

const obj = [null, 0, false, 1]
console.log(compactObject(obj));